<?php

namespace app\common\validate\xilujob;

use think\Db;
use think\Validate;

class Inform extends Validate
{
    /**
     * 验证规则
     */
    protected $rule = [
        'user_id|用户' => ['require', 'user_exist'],
        'job_id|职位' => ['require', 'job_exist'],
        'job_inform_type_id|举报类型' => ['require'],
        'content|举报原因' => ['require', 'length:1,500'],
        'contact|联系方式' => ['length:1,40']
    ];
    /**
     * 提示消息
     */
    protected $message = [
    ];
    /**
     * 验证场景
     */
    protected $scene = [
        'add'  => [],
        'edit' => [],
    ];

    protected function user_exist($value, $rule, $data) {
        return Db::name('user')->where('id', $value)->count() > 0 ? true:'用户不存在';
    }

    protected function job_exist($value, $rule, $data) {
        return Db::name('xilujob_job')->where('id', $value)->count() > 0 ? true : '职位不存在';
    }

}
